<?php
namespace app\controller\admin;

use app\BaseController;
use app\Request;
use think\facade\Config;
use think\facade\Db;


class User extends BaseController{
    public function login(Request $request)
    {
        $param = $request->param();
        $token = Request::instance()->header('token');
        $userModel = new \app\model\User();
        $res = $userModel->checkUser($token,$param);
        if($res['code']==2){
            return api_json(0,$res['msg'],'');
        }else{
            $checkToken = $res['data'];
        }
        $userInfo = $userModel->loginUser($checkToken,$param);
        return api_json(20000,'请求数据成功',$userInfo);
    }
    public function register(Request $request)
    {
        $param = $request->param();
        $userModel = new \app\model\User();
        $res = $userModel->createUser($param);
        return api_json(20000,'用户注册成功',$res);
    }
    public function info(Request $request)
    {
        $param = $request->param();
        $member = Db::name("scale_user")
            ->where('token', "admin_token");

        $member = $member->select();

        return api_json(20000,'请求数据成功',$member);
    }
    public function logout()
    {
        return api_json(20000,"退出成功",'success');
    }

}
